package com.journaldev.spring.model;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name="user_info")
public class UserInfo {

	public UserInfo() {
		
	}
	
	@Id
	@Column(name="id")
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;

	public void setId(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}
	
	@Column(name="user_name")
	private String userName;

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	@Column(name="password")
	private String passWord;

	public String getPassWord() {
		return passWord;
	}

	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}
	
	@Column(name="ho_ten")
	private String fullName;

	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}
	
	@OneToOne(fetch = FetchType.EAGER)
	// Remember to add mappedBy on the @OneToOne annotation to ensure that only one side manages the relationship. 
	@JoinColumn(name = "id_phongkham")
	private PersonalOffice ownOffice;

	public PersonalOffice getOwnOffice() {
		return ownOffice;
	}

	public void setOwnOffice(PersonalOffice ownOffice) {
		this.ownOffice = ownOffice;
	}
	
	//orphanRemoval : when set to true , and delete 1 object in set ==> delete that object in db too
	@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "belongToDoctor", orphanRemoval = true)
	private Set<Patient> patents;
	
	//orphanRemoval : when set to true , and delete 1 object in set ==> delete that object in db too
	@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "drugsBelongToDoctor", orphanRemoval = true)
	private Set<Medicine> medicines;

	public Set<Medicine> getMedicines() {
		return medicines;
	}

	public void setMedicines(Set<Medicine> medicines) {
		this.medicines = medicines;
	}

	public Set<Patient> getPatents() {
		return patents;
	}

	public void setPatents(Set<Patient> patents) {
		this.patents = patents;
	}
	
}
